package tutorial.basic_sql;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import public_util.model.PublicAgentInfo;
import public_util.model.ReturnData;
import public_util.servlet.ServletParent;
import public_util.tool_4_handle.Tool_4_Servlet;
import system_api_4_trade.dao.ApiPublicMiddleTableMapper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

public class DBOperation {

    private static Logger logger = Logger.getLogger(DBOperation.class);



    /**
     * 推荐在具体方法里面, 完成SQL的open和close
     */
    public static ReturnData auth(SqlSessionFactory sqlSession, ServletParent thisParent, HttpServletResponse response, HttpServletRequest request){
        logger.info("----showDemo----");
        SqlSession session = sqlSession.openSession();

        ApiPublicMiddleTableMapper middleTableMapper = session.getMapper(ApiPublicMiddleTableMapper.class);

        ReturnData data = new ReturnData();
        HashMap<String, Object> mapData = new HashMap<String, Object>();
        PublicAgentInfo centerAgentInfo = null;
        try{
            //获取到界面的基本信息
            String token = "aaaaaa";
            String appId = "appId";
            String secret = "secret";
            HashMap<String, Object> paraPrice = new HashMap<>();
            ReturnData returnData = tutorial.lite_mod.system_use.auth_access.TemplateUtilApi.generate_auth_info(session,middleTableMapper, token, appId, secret, 30, paraPrice);
            if (returnData != null && returnData.getStatus() != 0)
            {
                return returnData;
            }
            HashMap<String, Object> para = new HashMap<>();
            session.commit();
        }
        catch(Exception e)
        {
            String msg = Tool_4_Servlet.showStackTrace(e);
            data.setMsg(msg);
        }
        finally
        {
            session.close();
        }
        logger.info("Landing success");
        return data;
    }


}
